﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using System.Windows.Media.Animation;

namespace Siderys.Blog.Search.UI.WPF
{
    /// <summary>
    /// Interaction logic for ResultItem.xaml
    /// </summary>
    public partial class ResultItem : UserControl
    {
        public static readonly RoutedEvent ShowCompletedEvent = EventManager.RegisterRoutedEvent(
        "ShowCompleted", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ResultItem));

        public event RoutedEventHandler ShowCompleted
        {
            add { AddHandler(ShowCompletedEvent, value); }
            remove { RemoveHandler(ShowCompletedEvent, value); }
        }

        void RaiseShowCompletedEvent()
        {
            RoutedEventArgs newEventArgs = new RoutedEventArgs(ResultItem.ShowCompletedEvent, this);
            RaiseEvent(newEventArgs);
        }

        private string mTitle;

        public string Title
        {
            get { return mTitle; }
            set { mTitle = value;
            this.txtTitle.Text = mTitle;
            }
        }
        private string mPath;

        public string Path
        {
            get { return mPath; }
            set { 
                mPath = value;
                this.lnk.NavigateUri = new Uri(mPath);
                this.txtLink.Text = mPath;
            }
        }

        public ResultItem()
        {
            InitializeComponent();
            
        }

        public ResultItem(string pTitle, string pPath)
        {
            InitializeComponent();
            this.Title = pTitle;
            this.Path = pPath;

        }

        void HandleRequestNavigate(object sender, RoutedEventArgs e)
        {
            string navigateUri = lnk.NavigateUri.ToString();
            // if the URI somehow came from an untrusted source, make sure to
            // validate it before calling Process.Start(), e.g. check to see
            // the scheme is HTTP, etc.
            Process.Start(new ProcessStartInfo(navigateUri));
            e.Handled = true;
        }

        private void Storyboard_Completed(object sender, EventArgs e)
        {
            RaiseShowCompletedEvent();
        }

        internal void Show()
        {
            ((Storyboard)this.Resources["StoryShow"]).Begin();
        }
    }
}
